const singer = [{
		name: '周杰伦',
		age: 34
	},
	{
		name: '许嵩',
		age: 34
	},
	{
		name: '邓紫棋',
		age: 44
	},
	{
		name: '张碧晨',
		age: 44
	},
	{
		name: '薛之谦',
		age: 44
	},
	{
		name: '封茗囧菌',
		age: 44
	},
]
Array.prototype.my_reduce = function(callback, ...args) {
	let pre, start = 0;
	if (args.length) {
		pre = args[0]
	} else {
		pre = this[0]
		start = 1
	}

	for (let i = start; i < this.length; i++) {
		pre = callback(pre, this[i], i, this)
	}
	return pre
}

// 1
// const newSinger = singer.reduce((total, value, index, array) => {
// 	console.log(total, index, value);
// })
// console.log(newSinger); 

// 2
// const newSinger = singer.reduce((total, value, index, array) => {
// 	console.log(total, index, value);
// }, 0)
// console.log(newSinger);

// 3
// const newSinger = singer.reduce((total, value, index, array) => {
// 	return total + value.age
// }, 0)
// console.log(newSinger); //244

// 4
// const newSinger = singer.reduce((total, value, index, array) => {
// 	console.log(total);
// 	return total + value.age
// })
// console.log(newSinger); //244

// 5
const newSinger = singer.my_reduce((total, value, index, array) => {
	console.log(total);
	return total + value.age
}, 0)
console.log(newSinger); //244
